php return json

41

how to receive json data in php -

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;

php get json array -

$json = '
{
    "type": "donut",
    "name": "Cake",
    "toppings": [
        { "id": "5002", "type": "Glazed" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5004", "type": "Maple" }
    ]
}';

$yummy = json_decode($json, true);

echo $yummy['toppings'][2]['type']; //Maple

Comments

Submit
0 Comments